package com.longrise.android.byjk.plugins.tabsecond;

import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.design.widget.TabLayout;
import android.support.v4.view.PagerAdapter;
import android.support.v4.view.ViewPager;
import android.view.ViewGroup;

import com.longrise.android.byjk.R;
import com.longrise.android.byjk.model.AllCourseParentBean;
import com.longrise.common.base.BaseFragment;
import com.longrise.common.utils.PrintLog;
import com.longrise.common.utils.UmengStatisticsUtil;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by callxkj on 2017/10/22.
 * 第二个tab页面
 */

public class SecondFragment extends BaseFragment<SecondPresenter> implements SecondContract.View {

    private static final String TAG = "SecondFragment";
    private TabLayout mTb;
    private ViewPager mVp;
    private List<AllCourseParentBean> mParentBeanList = new ArrayList<>();

    @Override
    protected int getLayoutResourse(@Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        return R.layout.fragment_second;
    }

    @Override
    public void initView() {
        mTb = (TabLayout) mRootView.findViewById(R.id.fragment_second_tablayout);
        mVp = (ViewPager) mRootView.findViewById(R.id.fragment_second_viewpager);

        UmengStatisticsUtil.onEvent("ins_physic_system" + (1)); //首次进来 默认选择第一页
    }

    @Override
    public void showLoadingDialog() {

    }

    @Override
    public void dismissLoadingDialog() {

    }

    @Override
    public void initAdapter(List<AllCourseParentBean> parentList) {
        mParentBeanList.clear();
        mParentBeanList.addAll(parentList);

        SecondFragmentPagerAdapter pagerAdapter = new SecondFragmentPagerAdapter(mActivity.getSupportFragmentManager());
        pagerAdapter.setData(mParentBeanList);
        mVp.setAdapter(pagerAdapter);
        mTb.setupWithViewPager(mVp);

        mVp.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
            @Override
            public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {

            }

            @Override
            public void onPageSelected(int position) {
                UmengStatisticsUtil.onEvent("ins_physic_system" + (position + 1));
            }

            @Override
            public void onPageScrollStateChanged(int state) {

            }
        });
    }
}
